package com.codinghero.zqlb.spider.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.codinghero.util.StringUtils;
import com.codinghero.zqlb.spider.bo.GenMatchPageBo;

public class GenMatchPageServlet extends HttpServlet {

	private static final long serialVersionUID = 3633293872945315636L;

	private GenMatchPageBo genMatchPageBo = new GenMatchPageBo();

	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {

		String matchTypesStr = req.getParameter("matchTypes");
		String matchPageStr = null;

		if (StringUtils.isEmpty(matchTypesStr)) {
			matchPageStr = genMatchPageBo.genAllMatches();
		} else {
			String[] matchTypeArr = matchTypesStr.split(",");
			Integer[] matchTypes = new Integer[matchTypeArr.length];
			for (int i = 0; i < matchTypes.length; i++) {
				matchTypes[i] = Integer.parseInt(matchTypeArr[i]);
			}
			matchPageStr = genMatchPageBo.getMatchPageStr(matchTypes);
		}

		resp.setCharacterEncoding("UTF-8");
		PrintWriter out = resp.getWriter();
		out.println(matchPageStr);
		out.print("success");
	}
}
